<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //同时将数组中多个值分别赋给a,b,c
        let arr = [1, 2, 3];
        let [a, b, c] = arr;

        //交互变量值
        let x = 1, y = 2;
        [y, x] = [x, y];
        console.log(x, y); //2,1

        //只赋一个值给d
        let [, , d] = arr;
        console.log(d); //3

        //从嵌套数组中将1赋给e，3赋给f，5赋给g
        let arrs = [1, [2, 3, 4], 5, 6];
        let [e, [, f,], g] = arrs;
        console.log(e, f, g); //1,3,5

        //设置默认值，右边赋值对象为空，默认值生效，否则照常赋值
        let [h = 1] = []; //let [h=1]=[100] //h=100
        console.log(h); //1
    </script>
</body>

</html>